<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>我接的活</title>
    <link rel="stylesheet" type="text/css" href="../../../css/aui/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/html/order/get_work_frm.css" />
    <style>
        .aui-checkbox {
            width: 0.6rem;
            height: 0.6rem;
            margin-top: 0.15rem;
            margin-left: 0.5rem;
            border-radius: 50%;
        }

        .statement {
            color: #0689FB;
            margin-right: 0.5rem;
        }

        .iconimg {
            width: 0.6rem;
            display: inline-block;
        }

        .btn {
            margin-left: 0.2rem;
        }

        .aui-badge {
            top: 0.1rem;
        }

        [v-clock] {
            display: none;
        }
    </style>
</head>

<body>
    <div id="app" v-clock>
        <div class="tab_nav">
            <div class="aui-tab border_b" id="tab">
                <div class="aui-tab-item aui-active">待报价
                    <div class="aui-badge" v-if="contData.status1>0 && contData.status1<100">{{contData.status1}}</div>
                    <div class="aui-badge" v-else-if="contData.status1>99">{{contData.status1}}</div>
                </div>
                <div class="aui-tab-item">待支付
                    <div class="aui-badge" v-if="contData.status2>0 && contData.status2<100">{{contData.status2}}</div>
                    <div class="aui-badge" v-else-if="contData.status2>99">{{contData.status2}}</div>
                </div>
                <div class="aui-tab-item">待服务
                    <div class="aui-badge" v-if="contData.status3>0 && contData.status3<100">{{contData.status3}}</div>
                    <div class="aui-badge" v-else-if="contData.status3>99">{{contData.status3}}</div>
                </div>
                <div class="aui-tab-item">服务中
                    <div class="aui-badge" v-if="contData.status4>0 && contData.status4<100">{{contData.status4}}</div>
                    <div class="aui-badge" v-else-if="contData.status4>99">{{contData.status4}}</div>
                </div>
                <div class="aui-tab-item">待验收
                    <div class="aui-badge" v-if="contData.status5>0 && contData.status5<100">{{contData.status5}}</div>
                    <div class="aui-badge" v-else-if="contData.status5>99">{{contData.status5}}</div>
                </div>
                <div class="aui-tab-item">已完成
                    <div class="aui-badge" v-if="contData.status6>0 && contData.status6<100">{{contData.status6}}</div>
                    <div class="aui-badge" v-else-if="contData.status6>99">{{contData.status6}}</div>
                </div>
                <div class="aui-tab-item">已取消
                    <div class="aui-badge" v-if="contData.status0>0 && contData.status0<100">{{contData.status0}}</div>
                    <div class="aui-badge" v-else-if="contData.status0>99">{{contData.status0}}</div>
                </div>
            </div>
        </div>
        <div id="tab-item-content">
            <div class="tab-content">
                <div v-for="o,i in list">
                    <div class="aui-list" @click="openWin('particulars',{id:o.work_id,isMobile:true})">
                        <div class="aui-list-item">
                            <div class="aui-list-item-inner">
                                <div class="aui-list-item-title aui-ellipsis-1">{{o.title}}</div>
                            </div>
                        </div>
                        <div class="aui-list-item">
                            <div class="aui-media-list-item-inner">
                                <div class="aui-list-item-media">
                                    <img :src="o.headimgurl" style="border-radius:50%;overflow:hidden;border:1px solid #eee;">
                                </div>
                                <div class="person_info">
                                    <div> <img src="../../../image/icon/menu02-1.png" class="iconimg" alt=""> <span>联系人：{{o.contact}}</span></div>
                                    <div> <img src="../../../image/icon/daohang.png" class="iconimg" alt=""> <span>项目地点：{{o.region}}</span></div>
                                    <div> <img src="../../../image/icon/time.png" class="iconimg" alt=""> <span>发布时间：{{o.work_date}}</span></div>
                                </div>
                            </div>
                        </div>
                        <div v-if="listType!==1">
                            <div class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-title">所需工期</div>
                                    <div class="aui-list-item-right" style="color:#212121;">{{o.work_time}}天</div>
                                </div>
                            </div>
                            <div class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-title">所需费用</div>
                                    <div class="aui-list-item-right" style="color:#212121;">{{o.order_price}}元</div>
                                </div>
                            </div>
                            <div class="aui-list-item" v-if="(listType === 5 && o.is_refund > 0) || (listType === 6 && o.is_refund == 2)">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-title">退款差价</div>
                                    <div class="aui-list-item-right" style="color:#212121;">{{o.refund_price}}元</div>
                                </div>
                            </div>
                        </div>
                    </div>


                    <div class="btn-group" v-if="listType===1">
                        <div class="btn" @click="cancel(o,i)">取消</div>
                        <div class="btn" @click="openWin('to_quote',o)">去报价</div>
                    </div>
                    <div class="btn-group" v-if="listType===2">
                        <div class="btn" @click="cancel(o,i)">取消</div>
                    </div>
                    <div class="btn-group" v-if="listType===3">
                        <div class="btn" @click="startService(o,i)">开始服务</div>
                    </div>
                    <div class="btn-group" v-if="listType===4">
                        <div class="btn" @click="openWin('release_progress',o)">发布进度</div>
                        <div class="btn" @click="inviteAccept(o,i)">请客户验收</div>
                    </div>
                    <div class="btn-group" v-if="listType===5">
                        <div class="btn" v-if="o.is_refund===1" @click="agreeRefund(o,i)">同意退差价</div>
                        <div class="btn" v-if="o.is_refund===2">差价已退</div>
                    </div>
                    <div class="btn-group" v-if="listType===6">
                        <div class="btn" v-if="o.is_comment===1" @click="openWin('comment_details',o)">查看评价</div>
                    </div>

                </div>
            </div>

        </div>
    </div>
</body>
<script src="../../../script/api.js" charset="utf-8"></script>
<script src="../../../script/aui/aui-tab.js" charset="utf-8"></script>
<script src="../../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../../script/common/common.js" charset="utf-8"></script>
<script src="../../../script/common/config.js" charset="utf-8"></script>
<script src="../../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    apiready = function() {
        api.parseTapmode();
        vm.init();
    }

    var vm = new Vue({
        el: "#app",
        data: {
            list: [],
            contData: {},

            listType: 1,
            listPage: 1,
            listStatus: true
        },
        methods: {
            init() {
                this.userInfo = get_local("userInfo");
                this.tabChange();
                this.upDownLoad();
                this.getList();

                this.getContData();
            },
            getList() {
                var that = this;
                var urls = {
                    1: Config.api.AcceptUserWaitOffer,
                    2: Config.api.AcceptUserWaitPay,
                    3: Config.api.AcceptUserWaitService,
                    4: Config.api.AcceptUserInService,
                    5: Config.api.AcceptUserWaitAccept,
                    6: Config.api.AcceptUserComplete,
                    7: Config.api.AcceptUserCancelOffer,
                };
                var data = {
                    accept_user_id: that.userInfo.user_id,
                    pages: that.listPage
                };
                _ajax(urls[that.listType], data, function(ret) {
                    if (ret.code === 200) {
                        if (that.listPage === 1) {
                            that.list = ret.data;
                        } else {
                            if (ret.data.length > 0) {
                                that.list = that.list.concat(ret.data);
                            } else {
                                that.listStatus = false;
                            }
                        }
                    }
                });
            },
            getContData() {
                var self = this;
                _ajax(Config.api.AcceptUserGetTotal, {
                    accept_user_id: this.userInfo.user_id
                }, function(res) {
                    if (res.code === 200) {
                        self.contData = res.data;
                    }
                })
            },
            cancel(o, i) {
                var that = this;
                var data = {
                    order_id: o.order_id,
                    work_id: o.work_id,
                    work_user_id: o.work_user_id,
                    accept_user_id: o.accept_user_id,
                };
                _ajax(Config.api.AcceptUserCancel, data, function(ret) {
                    if (ret.code === 200) {
                        $toast("取消成功");
                        that.getContData();
                        that.list.splice(i, 1);
                    }
                });
            },
            startService(o, i) {
                var that = this;
                var data = {
                    order_id: o.order_id,
                    work_id: o.work_id,
                    work_user_id: o.work_user_id,
                    accept_user_id: o.accept_user_id,
                };
                _ajax(Config.api.AcceptUserBeginService, data, function(ret) {
                    if (ret.code === 200) {
                        $toast("更新服务状态成功");
                        that.getContData();
                        that.list.splice(i, 1);
                    }
                });
            },
            inviteAccept(o, i) {
                var that = this;
                var data = {
                    order_id: o.order_id,
                    work_id: o.work_id,
                    work_user_id: o.work_user_id,
                    accept_user_id: o.accept_user_id,
                };
                _ajax(Config.api.AcceptUserInviteAccept, data, function(ret) {
                    if (ret.code === 200) {
                        $toast("更新服务状态成功");
                        that.getContData();
                        that.list.splice(i, 1);
                    }
                });
            },
            agreeRefund(o, i) {
                var that = this;
                var data = {
                    order_id: o.order_id,
                    work_id: o.work_id,
                    work_user_id: o.work_user_id,
                    accept_user_id: o.accept_user_id,
                    refund_price: o.refund_price,
                };
                _ajax(Config.api.AcceptUserAgreeRefund, data, function(ret) {
                    if (ret.code === 200) {
                        $toast("已同意退差价");
                        that.list[i].is_refund = 2;
                    }
                });
            },
            tabChange() {
                var that = this;
                var tab = new auiTab({
                    element: document.getElementById("tab"),
                    index: 1,
                    repeatClick: false
                }, function(ret) {
                    that.list = [];
                    that.listType = ret.index;
                    that.listPage = 1;
                    that.listStatus = true;
                    that.getList();
                    that.getContData();
                });
            },
            upDownLoad() {
                var that = this;

                // 下拉刷新
                push_down(function() {
                    //下拉刷新恢复
                    push_down_over();
                    that.listStatus = true;
                    that.listPage = 1;
                    that.getList();
                });

                //上拉加载
                push_up(function() {
                    if (that.listStatus) {
                        that.listPage++;
                        that.getList();
                    }
                });
            },
            openWin(name, o) {
                var winInfo = {
                    to_quote: {
                        name: 'to_quote_win',
                        url: './to_quote_win.html',
                        pageParam: o
                    },
                    pay: {
                        name: 'pay_win',
                        url: './pay_win.html',
                        pageParam: o
                    },
                    release_progress: {
                        name: 'release_progress_win',
                        url: './release_progress_win.html',
                        pageParam: o
                    },
                    comment_details: {
                        name: 'comment_details_win',
                        url: './comment_details_win.html',
                        pageParam: o
                    },
                    demand_details: {
                        name: 'demand_details',
                        url: './demand_details_win.html',
                        pageParam: o
                    },
                    particulars: {
                        name: 'demand_details_new_win',
                        url: '../../details/demand_details_new_win.html',
                        pageParam: o
                    },
                };
                if (name) {
                    open_w(winInfo[name].name, winInfo[name].url, winInfo[name].pageParam);
                } else {
                    $toast("正在开发中...");
                }
            }
        }
    });
</script>

</html>
